package cn.neusoft.controller;

import cn.neusoft.pojo.Business;
import cn.neusoft.query.BaseQuery;
import cn.neusoft.query.BusinessQuery;
import cn.neusoft.vo.PageBean;
import cn.neusoft.vo.ResultBean;
import org.springframework.web.bind.annotation.*;

import javax.xml.transform.Result;
import java.util.Arrays;
import java.util.List;

/**
 * Restful风格的请求
 *   请求方式  +  请求路径
 * @XXMapping    /business[请求方式不同  只写模块路径即可]
 *                        [请求方式相同  给模块路径后面再加访问内容路径]
 *
 * add     添加         post   /business
 * update  修改         put    /business
 * del     删除       delete  /business/1003
 * getById  通过id查询  get   /business/1003
 * getByPage 分页查询   post  /business/page
 */
@RestController
@RequestMapping("/business")
public class BusinessController {

	@PostMapping      //  请求方式 + 请求路径   post  /business
	public ResultBean add(@RequestBody Business business){
		System.out.println("----BusinessController-----add--------");
		System.out.println(business);
		return ResultBean.SUCCESS("add success");
	}

	@PutMapping    //   put   /business
	public ResultBean update(@RequestBody Business business){
		System.out.println("-------BusinessController--------update-------------");
		System.out.println(business);
		return ResultBean.SUCCESS("update success");
	}

	//  delete   /business/1003
	@DeleteMapping("/{empno}")   // http://localhost:8080/business/1003
	public ResultBean del(@PathVariable("empno") Integer empno){
		System.out.println("-------BusinessController--------del-------------");
		System.out.println(empno);
		return ResultBean.SUCCESS("delete success");
	}

	//  get   /business/1004
	@GetMapping("/{empno}")   // http://localhost:8080/business/1003
	public ResultBean getById(@PathVariable("empno") Integer empno){
		System.out.println("-------BusinessController--------getById-------------");
		Business business=new Business();
		business.setBusinessAccount("djadja");
		business.setBusinessName("张三");
		business.setBusinessId(1001);
		business.setBusinessAddress("新乡市");
		return ResultBean.SUCCESS(business);
	}

	@PostMapping("/page")   // post  /business/page
	public ResultBean getByPage(@RequestBody BusinessQuery businessQuery){
		System.out.println("-------BusinessController--------getByPage-------------");
		BaseQuery baseQuery=new BaseQuery();
		baseQuery.setPageCount(5);
		baseQuery.setPageNow(1);
		List<Business> list = Arrays.asList(
				new Business(1001, "dhasjdhkas", "111111", "好利来", "新乡", "好吃", "", 18.0, 8.0, "无"),
				new Business(1002, "hjkjkljl", "111111", "幸运咖", "新乡", "好吃", "", 18.0, 8.0, "无"),
				new Business(1003, "ewqewqer", "111111", "瑞幸咖啡", "新乡", "好吃", "", 18.0, 8.0, "无")

		);
		PageBean<Business> pageBean=new PageBean<Business>();
		pageBean.setData(list);
		return ResultBean.SUCCESS(pageBean);
	}

}
